package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.igas.bomp.facade.enums.BompImageTypeEnum;
import cc.rengu.redp.bizimpl.enums.BizDataAuditStatusEnum;
import cc.rengu.redp.bizimpl.enums.BizDataStatusEnum;
import cc.rengu.redp.bizimpl.enums.BizOprEnum;
import cc.rengu.redp.bizimpl.enums.PageOptFlagEnum;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.dao.DirectMchntBaseInfoMapper;
import cc.rengu.redp.bizimpl.upmp.dao.DirectMchntImageInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.*;
import cc.rengu.redp.bizimpl.upmp.service.*;
import cc.rengu.redp.bizimpl.upmp.vo.DirectMchntImageManageVO;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.DateUtils;
import cc.rengu.redp.common.exception.RedpException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 刘玉亮.LL
 */
@Service
public class DirectMchntImageInfoServiceImpl extends ServiceImpl<DirectMchntImageInfoMapper, UpmpBMchntImageInfo> implements IDirectMchntImageInfoService {
    @Autowired
    private IUpmpOrganizationService organizationService;
    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Autowired
    private IUpmpPrivilegeCheckService upmpPrivilegeCheckService;
    @Autowired
    private IBizTmpService bizTmpService;
    @Autowired
    private IBizHisService bizHisService;

    @Autowired
    private IDirectMchntBaseInfoService directBaseInfoService;
    @Autowired
    private IDirectMchntSignInfoService directSignInfoService;
    @Override
    public List<UpmpBMchntImageInfo> getBMchntImageInfoByMchntNo(String mchntNo) {
        LambdaQueryWrapper<UpmpBMchntImageInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UpmpBMchntImageInfo::getMchntNo, mchntNo);
        return this.list(wrapper);
    }

    /**
     * 从 bMchntImageInfoList 转换成 directMchntImageManageVO
     *
     * @param bMchntImageInfoList      源数据
     * @param directMchntImageManageVO 目标数据
     */
    @Override
    public void transformDirectMchntImageManageVO(List<UpmpBMchntImageInfo> bMchntImageInfoList, DirectMchntImageManageVO directMchntImageManageVO) {
        if (null == directMchntImageManageVO) {
            directMchntImageManageVO = new DirectMchntImageManageVO();
        }
        //
        for (UpmpBMchntImageInfo mchntImage : bMchntImageInfoList) {
            mchntImage.setImagePath(mchntImage.getImageRemotePath());
            // 赋值商户号
            if (StringUtils.isBlank(directMchntImageManageVO.getMchntNo())) {
                directMchntImageManageVO.setMchntNo(mchntImage.getMchntNo());
            }
            if (StringUtils.isBlank(directMchntImageManageVO.getInstId())) {
                directMchntImageManageVO.setInstId(mchntImage.getInstId());
            }

            if (mchntImage.getImageType().equals(BompImageTypeEnum.BUSINESS_LICENSE.getImageType())) {
                //经营执照
                directMchntImageManageVO.setBusinessLicense(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.ARTIF_FACE_CERT_IMAGE.getImageType())) {
                //负责人身份证(人像面)
                directMchntImageManageVO.setFrontCert(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.ARTIF_BACK_CERT_IMAGE.getImageType())) {
                //负责人身份证(国徽面)
                directMchntImageManageVO.setReverseCert(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.HOLDING_CERT_PHOTO.getImageType())) {
                //负责人手持身份证
                directMchntImageManageVO.setHoldingCert(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.SHOP_FRONT_PHOTO.getImageType())) {
                //商户门头照
                directMchntImageManageVO.setShopFront(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.BUSINESS_SITE_PHOTO.getImageType())) {
                //经营场所照 list
                if (null == directMchntImageManageVO.getPremisesList()) {
                    directMchntImageManageVO.setPremisesList(new ArrayList<>());
                }
                directMchntImageManageVO.getPremisesList().add(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.CREDIT_AUTH.getImageType())) {
                //人行征信查询授权书 list
                if (null == directMchntImageManageVO.getCreditAuthList()) {
                    directMchntImageManageVO.setCreditAuthList(new ArrayList<>());
                }
                directMchntImageManageVO.getCreditAuthList().add(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.CREDIT_REPORT.getImageType())) {
                //征信报告 list
                if (null == directMchntImageManageVO.getCreditReportList()) {
                    directMchntImageManageVO.setCreditReportList(new ArrayList<>());
                }
                directMchntImageManageVO.getCreditReportList().add(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.NETWORK_VERIFY_REPORT.getImageType())) {
                //身份证联网核查报告 list
                if (null == directMchntImageManageVO.getNetworkVerifyList()) {
                    directMchntImageManageVO.setNetworkVerifyList(new ArrayList<>());
                }
                directMchntImageManageVO.getNetworkVerifyList().add(mchntImage);
            } else if (mchntImage.getImageType().equals(BompImageTypeEnum.OTHER_ELECTRON_IMAGE.getImageType())) {
                //其他电子资料文件 list
                if (null == directMchntImageManageVO.getOtherFileList()) {
                    directMchntImageManageVO.setOtherFileList(new ArrayList<>());
                }
                directMchntImageManageVO.getOtherFileList().add(mchntImage);
            }
        }
    }
    private void deleteBMchntImageInfoByMchntNo(String mchntNo){
        LambdaQueryWrapper<UpmpBMchntImageInfo> wrapper = new LambdaQueryWrapper();
        wrapper.eq(UpmpBMchntImageInfo::getMchntNo,mchntNo);
        this.baseMapper.delete(wrapper);
    }

    @Override
    @Transactional(value = "transactionManager")
    public OperationResult saveData(String oprMenuId, String oprMenuName, DirectMchntImageManageVO vo, HttpServletRequest request, String webNextUrl, String flag) throws RedpException {
        java.util.Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        UpmpOrganization org = organizationService.getOrgByCode(user.getOrgCode(), user.getInstId());

        if (StringUtils.isBlank(vo.getMchntSignId())) {
            log.error("请求参数(商户签约协议号)必填!");
            return OperationResult.buildFailureResult("请求参数(商户签约协议号)必填!", result);
        }

        // 对象转换
        List<UpmpBMchntImageInfo> bMchntImageInfoList = new ArrayList<>();
        this.transformBMchntImageInfo(vo, bMchntImageInfoList);
        if (bMchntImageInfoList.size() <= 0) {
            log.error("请求参数(DirectMchntImageManageVO)异常!");
            return OperationResult.buildFailureResult("请求参数(DirectMchntImageManageVO)异常!", result);
        }
        //
        if (PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(flag)) {
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(vo.getInstId(), "银联直连商户管理:新增");
            // 重复新增，先清空，后新增
            this.deleteBMchntImageInfoByMchntNo(vo.getMchntNo());

            bizTmpService.deleteBizTmpByMchntNo(vo.getMchntNo(), "t_b_mchnt_image_info");
            // 修改签约信息表，商户签约协议号
            DirectMchntSignInfo directSignInfo = directSignInfoService.getByMchntCd(vo.getMchntNo());
            directSignInfo.setMchntSignId(vo.getMchntSignId());
            directSignInfoService.save(directSignInfo);

            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                // 入临时表
                bizTmpService.saveBizTmpDtl(directSignInfo, user, org.getInstId(),BizOprEnum.OPR_ADD.getType(), lastUpddt
                        , oprMenuId, oprMenuName, directSignInfo.getMchntSignStatus(), directSignInfo.getAuditStatus(), directSignInfo.getId(), webNextUrl, null, null, directSignInfo.getMchntCd(), null, null);
            }
            //
            for (UpmpBMchntImageInfo bMchntImageInfo : bMchntImageInfoList) {
                bMchntImageInfo.setId(null);
                bMchntImageInfo.setInstId(user.getInstId());
                bMchntImageInfo.setMchntNo(vo.getMchntNo());
                bMchntImageInfo.setLastOprId(user.getId());
                bMchntImageInfo.setLastUpdateTime(lastUpddt);
                // 非正式  新增-待提交审批
                bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType());
                // 入正式表
                this.save(bMchntImageInfo);
                //
                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    // 入临时表
                    bizTmpService.saveBizTmpDtl(bMchntImageInfo, user, org.getInstId(),BizOprEnum.OPR_ADD.getType(), lastUpddt
                            , oprMenuId, oprMenuName, BizDataStatusEnum.STATUS_DRAFT.getType(), bMchntImageInfo.getAuditStatus(), bMchntImageInfo.getId(), webNextUrl, "", "", bMchntImageInfo.getMchntNo(), null, null);
                } else {
                    // 录入历史表，状态改为 正式 新增-审核通过；
                    bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_PASS.getType());
                    bizHisService.saveBizHisNew(bMchntImageInfo, bMchntImageInfo, user, org.getInstId(),BizOprEnum.OPR_ADD.getType(), lastUpddt
                            , oprMenuId, oprMenuName, bMchntImageInfo.getId(), bMchntImageInfo.getMchntNo(), null, null);
                }
            }
            result.put("mchntCd", vo.getMchntNo());
        } else if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(flag)) {
            // 上一次操作如果是新增-待提交审批的，前端传来upd标志，转到add方法处理
            DirectMchntBaseInfo directBaseInfo = directBaseInfoService.getByMchntCd(vo.getMchntNo());
            if (directBaseInfo.getAuditStatus().equals(BizDataAuditStatusEnum.AUDIT_STATUS_ADD_NOTCOMMIT.getType())) {
                //
                return this.saveData(oprMenuId, oprMenuName, vo, request, webNextUrl, "add");
            }
            //
            String auditStatus = BizDataAuditStatusEnum.AUDIT_STATUS_UPD_NOTCOMMIT.getType();
            UpmpPrivilegeCheck privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(vo.getInstId(), "银联直连商户管理:修改");
            for (UpmpBMchntImageInfo entity : bMchntImageInfoList) {
                String id = entity.getId();
                if (Common.isBlank(id)) {
                    log.error("请求参数(id)异常!");
                    return OperationResult.buildFailureResult("请求参数(id)异常!", result);
                }
                UpmpBMchntImageInfo dbBMchntImageInfo = this.getById(id);
                UpmpBMchntImageInfo bMchntImageInfo = new UpmpBMchntImageInfo();
                BeanUtils.copyProperties(entity, bMchntImageInfo);

                entity.setLastOprId(user.getId());
                entity.setLastUpdateTime(lastUpddt);

                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    dbBMchntImageInfo.setLastOprId(user.getId());
                    dbBMchntImageInfo.setLastUpdateTime(lastUpddt);
                    // 修改-待提交审批
                    dbBMchntImageInfo.setAuditStatus(auditStatus);

                    this.updateById(dbBMchntImageInfo);

                    //检查临时表是否有数据，如果没用则新增
                    entity.setAuditStatus(auditStatus);
                    bMchntImageInfo = new UpmpBMchntImageInfo();
                    BeanUtils.copyProperties(dbBMchntImageInfo, bMchntImageInfo);
                    BeanUtils.copyProperties(entity, bMchntImageInfo);

                    bizTmpService.saveBizTmpDtl(bMchntImageInfo, user, org.getInstId(),BizOprEnum.OPR_UPDATE.getType(), lastUpddt
                            , oprMenuId, oprMenuName, BizDataStatusEnum.STATUS_DRAFT.getType(), bMchntImageInfo.getAuditStatus(), bMchntImageInfo.getId(), webNextUrl, "", "", bMchntImageInfo.getMchntNo(), null, null);
                } else {
                    // 修改-待提交审批
                    entity.setAuditStatus(auditStatus);

                    BeanUtils.copyProperties(entity, bMchntImageInfo);
                    this.updateById(bMchntImageInfo);

                    // 录入历史表，状态改为 正式 修改-审核通过；
                    bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                    //历史表新增
                    bizHisService.saveBizHisNew(bMchntImageInfo, dbBMchntImageInfo, user, org.getInstId(),BizOprEnum.OPR_UPDATE.getType(), lastUpddt
                            , oprMenuId, oprMenuName, bMchntImageInfo.getId(), bMchntImageInfo.getMchntNo(), null, null);
                }
                result.put("id", bMchntImageInfo.getId());
                result.put("mchntCd", bMchntImageInfo.getMchntNo());
            }
        } else if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(flag)
                || PageOptFlagEnum.OPT_FLAG_USE.getType().equals(flag)
                || PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(flag)) {
            UpmpPrivilegeCheck privilegeCheck;
            for (UpmpBMchntImageInfo entity : bMchntImageInfoList) {
                String id = entity.getId();
                if (Common.isBlank(id)) {
                    log.error("请求参数(id)异常!");
                    return OperationResult.buildFailureResult("请求参数(id)异常!", result);
                }
                UpmpBMchntImageInfo dbBMchntImageInfo = this.getById(id);
                if (null == dbBMchntImageInfo) {
                    log.error("根据id没有找到指定数据！");
                    return OperationResult.buildFailureResult("根据id没有找到指定数据！", result);
                }

                UpmpBMchntImageInfo bMchntImageInfo = new UpmpBMchntImageInfo();
                BeanUtils.copyProperties(dbBMchntImageInfo, bMchntImageInfo);
                //
                privilegeCheck = new UpmpPrivilegeCheck();
                String bizOpr = "";
                if (PageOptFlagEnum.OPT_FLAG_STOP.getType().equals(flag)) {
                    bizOpr = BizOprEnum.OPR_STOP.getType();
                    privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(vo.getInstId(), "银联直连商户管理:停用");
                    if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                        // 停用-待提交审批
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_NOTCOMMIT.getType());
                    } else {
                        // 停用-审核通过
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_STOP_PASS.getType());
                    }
                } else if (PageOptFlagEnum.OPT_FLAG_USE.getType().equals(flag)) {
                    bizOpr = BizOprEnum.OPR_USE.getType();
                    privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(vo.getInstId(), "银联直连商户管理:启用");
                    if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                        // 启用-待提交审批
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_NOTCOMMIT.getType());
                    } else {
                        // 启用-审核通过
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_USE_PASS.getType());
                    }
                } else if (PageOptFlagEnum.OPT_FLAG_CANCEL.getType().equals(flag)) {
                    bizOpr = BizOprEnum.OPR_CANCEL.getType();
                    privilegeCheck = upmpPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(vo.getInstId(), "银联直连商户管理:注销");
                    if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                        // 注销-待提交审批
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_NOTCOMMIT.getType());
                    } else {
                        // 注销-审核通过
                        bMchntImageInfo.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_CANCEL_PASS.getType());
                    }
                }
                bMchntImageInfo.setLastOprId(user.getId());
                bMchntImageInfo.setLastUpdateTime(lastUpddt);
                this.updateById(bMchntImageInfo);

                if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                    //检查临时表是否有数据，如果没用则新增
                    bizTmpService.saveBizTmpDtl(bMchntImageInfo, user, org.getInstId(),bizOpr, lastUpddt
                            , oprMenuId, oprMenuName, BizDataStatusEnum.STATUS_DRAFT.getType(), bMchntImageInfo.getAuditStatus(), bMchntImageInfo.getId(), webNextUrl, "", "", bMchntImageInfo.getMchntNo(), null, null);
                } else {
                    //历史表新增
                    bizHisService.saveBizHisNew(entity, bMchntImageInfo, user, org.getInstId(),bizOpr, lastUpddt
                            , oprMenuId, oprMenuName, bMchntImageInfo.getId(), bMchntImageInfo.getMchntNo(), null, null);
                }

                result.put("id", bMchntImageInfo.getId());
                result.put("mchntCd", bMchntImageInfo.getMchntNo());
            }
        }

        result.put("formNm", "imageInfo");
        if(!PageOptFlagEnum.OPT_FLAG_ADD.getType().equals(flag)&&!PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(flag)){
            return OperationResult.buildSuccessResult("", result);
        }else{
            return OperationResult.buildSuccessResult("数据保存处理完成", result);
        }
    }

    /**
     * 从 directMchntImageManageVO 转换成 bMchntImageInfoList
     *
     * @param directMchntImageManageVO 源数据
     * @param bMchntImageInfoList      目标数据
     */
    public void transformBMchntImageInfo(DirectMchntImageManageVO directMchntImageManageVO, List<UpmpBMchntImageInfo> bMchntImageInfoList) {
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");

        if (null == bMchntImageInfoList) {
            bMchntImageInfoList = new ArrayList<>();
        }
        if(Common.isNotBlank(directMchntImageManageVO.getBusinessLicense()) && Common.isNotBlank(directMchntImageManageVO.getBusinessLicense().getImageLocalPath())) {
            //经营执照
            UpmpBMchntImageInfo businessLicense = directMchntImageManageVO.getBusinessLicense();
            businessLicense.setInstId(directMchntImageManageVO.getInstId());
            businessLicense.setMchntNo(directMchntImageManageVO.getMchntNo());
            businessLicense.setOprId(user.getId());
            businessLicense.setCreateTime(lastUpddt);
            businessLicense.setImageRemotePath(businessLicense.getImagePath());
            bMchntImageInfoList.add(businessLicense);
        }
        if(Common.isNotBlank(directMchntImageManageVO.getFrontCert()) && Common.isNotBlank(directMchntImageManageVO.getFrontCert().getImageLocalPath())) {
            //负责人身份证(人像面)
            UpmpBMchntImageInfo frontCert = directMchntImageManageVO.getFrontCert();
            frontCert.setInstId(directMchntImageManageVO.getInstId());
            frontCert.setMchntNo(directMchntImageManageVO.getMchntNo());
            frontCert.setOprId(user.getId());
            frontCert.setCreateTime(lastUpddt);
            frontCert.setImageRemotePath(frontCert.getImagePath());
            bMchntImageInfoList.add(frontCert);
        }

        if(Common.isNotBlank(directMchntImageManageVO.getReverseCert()) && Common.isNotBlank(directMchntImageManageVO.getReverseCert().getImageLocalPath())) {
            //负责人身份证(国徽面)
            UpmpBMchntImageInfo reverseCert = directMchntImageManageVO.getReverseCert();
            reverseCert.setInstId(directMchntImageManageVO.getInstId());
            reverseCert.setMchntNo(directMchntImageManageVO.getMchntNo());
            reverseCert.setOprId(user.getId());
            reverseCert.setCreateTime(lastUpddt);
            reverseCert.setImageRemotePath(reverseCert.getImagePath());
            bMchntImageInfoList.add(reverseCert);
        }

        if(Common.isNotBlank(directMchntImageManageVO.getHoldingCert()) && Common.isNotBlank(directMchntImageManageVO.getHoldingCert().getImageLocalPath())) {
            //负责人手持身份证
            UpmpBMchntImageInfo holdingCert = directMchntImageManageVO.getHoldingCert();
            holdingCert.setInstId(directMchntImageManageVO.getInstId());
            holdingCert.setMchntNo(directMchntImageManageVO.getMchntNo());
            holdingCert.setOprId(user.getId());
            holdingCert.setCreateTime(lastUpddt);
            holdingCert.setImageRemotePath(holdingCert.getImagePath());
            bMchntImageInfoList.add(holdingCert);
        }

        if(Common.isNotBlank(directMchntImageManageVO.getShopFront()) && Common.isNotBlank(directMchntImageManageVO.getShopFront().getImageLocalPath())) {
            //商户门头照
            UpmpBMchntImageInfo shopFront = directMchntImageManageVO.getShopFront();
            shopFront.setInstId(directMchntImageManageVO.getInstId());
            shopFront.setMchntNo(directMchntImageManageVO.getMchntNo());
            shopFront.setOprId(user.getId());
            shopFront.setCreateTime(lastUpddt);
            shopFront.setImageRemotePath(shopFront.getImagePath());
            bMchntImageInfoList.add(shopFront);
        }

        //经营场所照 list
        List<UpmpBMchntImageInfo> premisesList = directMchntImageManageVO.getPremisesList();
        for (UpmpBMchntImageInfo bMchntImageInfo : premisesList) {
            if(Common.isNotBlank(bMchntImageInfo.getImageLocalPath())) {
                bMchntImageInfo.setInstId(directMchntImageManageVO.getInstId());
                bMchntImageInfo.setMchntNo(directMchntImageManageVO.getMchntNo());
                bMchntImageInfo.setOprId(user.getId());
                bMchntImageInfo.setCreateTime(lastUpddt);
                bMchntImageInfo.setImageRemotePath(bMchntImageInfo.getImagePath());
                bMchntImageInfoList.add(bMchntImageInfo);
            }
        }

        //人行征信查询授权书 list
        List<UpmpBMchntImageInfo> creditAuthList = directMchntImageManageVO.getCreditAuthList();
        for (UpmpBMchntImageInfo bMchntImageInfo : creditAuthList) {
            if(Common.isNotBlank(bMchntImageInfo.getImageLocalPath())) {
                bMchntImageInfo.setInstId(directMchntImageManageVO.getInstId());
                bMchntImageInfo.setMchntNo(directMchntImageManageVO.getMchntNo());
                bMchntImageInfo.setOprId(user.getId());
                bMchntImageInfo.setCreateTime(lastUpddt);
                bMchntImageInfo.setImageRemotePath(bMchntImageInfo.getImagePath());
                bMchntImageInfoList.add(bMchntImageInfo);
            }
        }

        //征信报告 list
        List<UpmpBMchntImageInfo> creditReportList = directMchntImageManageVO.getCreditReportList();
        for (UpmpBMchntImageInfo bMchntImageInfo : creditReportList) {
            if(Common.isNotBlank(bMchntImageInfo.getImageLocalPath())) {
                bMchntImageInfo.setInstId(directMchntImageManageVO.getInstId());
                bMchntImageInfo.setMchntNo(directMchntImageManageVO.getMchntNo());
                bMchntImageInfo.setOprId(user.getId());
                bMchntImageInfo.setCreateTime(lastUpddt);
                bMchntImageInfo.setImageRemotePath(bMchntImageInfo.getImagePath());
                bMchntImageInfoList.add(bMchntImageInfo);
            }
        }

        //身份证联网核查报告 list
        List<UpmpBMchntImageInfo> networkVerifyList = directMchntImageManageVO.getNetworkVerifyList();
        for (UpmpBMchntImageInfo bMchntImageInfo : networkVerifyList) {
            if(Common.isNotBlank(bMchntImageInfo.getImageLocalPath())) {
                bMchntImageInfo.setInstId(directMchntImageManageVO.getInstId());
                bMchntImageInfo.setMchntNo(directMchntImageManageVO.getMchntNo());
                bMchntImageInfo.setOprId(user.getId());
                bMchntImageInfo.setCreateTime(lastUpddt);
                bMchntImageInfo.setImageRemotePath(bMchntImageInfo.getImagePath());
                bMchntImageInfoList.add(bMchntImageInfo);
            }
        }

        //其他电子资料文件 list
        List<UpmpBMchntImageInfo> otherFileList = directMchntImageManageVO.getOtherFileList();
        for (UpmpBMchntImageInfo bMchntImageInfo : otherFileList) {
            if(Common.isNotBlank(bMchntImageInfo.getImageLocalPath())) {
                bMchntImageInfo.setInstId(directMchntImageManageVO.getInstId());
                bMchntImageInfo.setMchntNo(directMchntImageManageVO.getMchntNo());
                bMchntImageInfo.setOprId(user.getId());
                bMchntImageInfo.setCreateTime(lastUpddt);
                bMchntImageInfo.setImageRemotePath(bMchntImageInfo.getImagePath());
                bMchntImageInfoList.add(bMchntImageInfo);
            }
        }
    }
}
